package ioc

import (
	"yuanxin-admin/internal/common/ioc/provide"

	"go.uber.org/dig"
)

var iocContainer *dig.Container

func GetContainer() *dig.Container {
	return iocContainer
}

func Inject[T any](i T) T {
	err := iocContainer.Invoke(func(i2 T) {
		i = i2
	})
	if err != nil {
		panic(err)
	}
	return i
}

func InitIocContainer() {
	container := dig.New()
	iocContainer = container
	err := provide.Provide(iocContainer)
	if err != nil {
		panic(err)
	}
}
